Functions for Process Management

process management

In this section we describe the p4 functions needed for basic creation and termination of processes.

p4_initenv
\begin{example}
int p4_initenv(argc,argv)
int *argc;
char **argv;
\end{example}
should be called by your program before an attempt is made to use any p4 procedures or data areas. We suggest making it the first executable statement in your program. p4_initenv parses the command line arguments and extracts the ones intended for p4 ignoring all others (see the discussion of command line arguments). Note that you pass the address of argc to p4_initenv so that it can actually remove its own arguments before your program looks at them.

p4_create
\begin{example}
int p4_create(fxn)
int (*fxn)();
\par
\findex{p4_create_procgroup}
int p4_create_procgroup()
\end{example}
There are two procedures that you can use to create processes in p4, p4_create_procgroup and p4_create. Processes created via p4_create are said to be ``user-managed'' whereas those created by p4_create_procgroup are ``p4-managed''. The p4-managed processes are automatically assigned unique id's (beginning with 0 for the big master), they have message queues allocated for them so that they can do message-passing, and they are able to run either on a shared-memory multiprocessor with the creating process or they can run on a separate machine. Processes created via p4_create do not have any of these advantages. They must develop their own id's, they cannot do message-passing, and they can only run on a shared-memory multiprocessor with the creating process. The only disadvantage of p4_create_procgroup is that you must build a procgroup file describing the set of required slave processes before the master program begins execution. This eliminates the possibility of determining late in the execution exactly how many processes you want to use to solve a problem. Generally, this is not a problem, especially since we can combine p4_create_procgroup and p4_create in the following way: You can use p4_create_procgroup to develop a network of processes that talk to each other via messages. Each of those processes can create further processes to help it out as necessary. The original set of processes communicate with their local slaves through shared data areas and with each other via message-passing.

p4_create receives one argument that is a pointer to a function. It creates a single new process that executes the indicated function. The new process may share data areas (in shared memory) with the parent process. However, the new process is not managed by the p4 system in the sense that it is not assigned an id, it cannot pass messages, etc. The only p4 procedure that deals with user-managed slaves is p4_create. No other procedures are even aware of their existence.

p4_create_procgroup reads your procgroup file to determine the number of slave processes to create and where they are to be placed. It builds a procgroup table that describes all created processes and gives a copy of the table to each process. The processes then use the table to discover how to communicate with each other (processes in a cluster can send messages directly through shared memory or some other vendor-specific mechanism), others communicate via sockets). An alternative method is to build the table in memory yourself and use p4_startup.

The effect of p4_create_procgroup can be obtained in another way if a system would prefer to use its own way of specifying the locations of processes. A user may allocate the procgroup data structure and then fill it in ``by hand'' rather than by reading a file in p4 procgroup format. The following procedures support this method of starting processes.

p4_alloc_procgroup
\begin{example}
struct p4_procgroup *p4_alloc_procgroup()
\end{example}
allocates a procgroup data structure of the form described in p4.h. The formats of individual entries (p4_procgroup_entry) are given there as well.

p4_startup
\begin{example}
int 4_startup(pg)
struct p4_procgroup *pg;
\end{example}
starts processes as specified by an an already-created procgroup data structure allocated by p4_alloc_procgroup and filled in by the user using the structures p4_procgroup_entry and p4_procgroup.

p4_wait_for_end
\begin{example}
VOID p4_wait_for_end()
\end{example}
is the p4 termination/cleanup procedure that you should invoke at the end of every execution of a program that uses p4. It does some termination processing and then waits for slave processes to end.

p4_get_my_id
\begin{example}
int p4_get_my_id()
\end{example}
returns an integer value representing the id of the process assigned by the p4 system. If the process is not a p4-managed process, the value (-1) is returned.

p4_num_total_ids
\begin{example}
int p4_num_total_ids()
\end{example}
returns an integer value indicating the total number of ids started by p4 in all clusters, including the big master and all remote masters.

p4_num_total_slaves
\begin{example}
int p4_num_total_slaves()
\end{example}
returns an integer value indicating the total number of processes started by p4 in all clusters, including all remote masters but not the big master.

Functions for Cluster Management, ,Functions for Process Management,p4 Functions for Managing Processes and Clusters